{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 随机数生成六个班的考试成绩，3门考试：Python、数学、语文。每个班50人"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [],
   "source": [
    "class1_score = np. random.randint(0,100,size=(50,3))\n",
    "class2_score = np. random.randint(0,100,size=(50,3))\n",
    "class3_score = np. random.randint(0,100,size=(50,3))\n",
    "class4_score = np. random.randint(0,100,size=(50,3))\n",
    "class5_score = np. random.randint(0,100,size=(50,3))\n",
    "class6_score = np. random.randint(0,100,size=(50,3))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 将六个班的考试成绩进行合并得到score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[57,  8, 58],\n",
       "       [75, 55, 87],\n",
       "       [10, 91, 47],\n",
       "       [ 4, 45,  0],\n",
       "       [91, 94, 26],\n",
       "       [52, 99, 37],\n",
       "       [52, 19, 46],\n",
       "       [63, 44, 85],\n",
       "       [46,  6, 86],\n",
       "       [49, 41, 54],\n",
       "       [26,  6, 59],\n",
       "       [16,  7, 27],\n",
       "       [27, 80, 43],\n",
       "       [42, 90, 54],\n",
       "       [54, 28, 33],\n",
       "       [18, 70, 46],\n",
       "       [30, 21, 66],\n",
       "       [21,  1, 45],\n",
       "       [72, 62, 68],\n",
       "       [38, 21, 20],\n",
       "       [56, 48, 42],\n",
       "       [56, 79,  3],\n",
       "       [52, 52, 41],\n",
       "       [51, 77,  3],\n",
       "       [68, 79, 21],\n",
       "       [20, 14, 92],\n",
       "       [32, 17, 69],\n",
       "       [13, 74, 24],\n",
       "       [75, 47, 68],\n",
       "       [88, 49, 86],\n",
       "       [87, 52,  4],\n",
       "       [98, 16, 12],\n",
       "       [ 9, 98, 70],\n",
       "       [78, 39, 13],\n",
       "       [18, 16, 11],\n",
       "       [10, 75, 54],\n",
       "       [50, 66, 47],\n",
       "       [15, 54, 83],\n",
       "       [65, 67, 29],\n",
       "       [77,  2, 78],\n",
       "       [97, 80, 89],\n",
       "       [49, 71, 21],\n",
       "       [85, 64,  0],\n",
       "       [81,  5, 15],\n",
       "       [99, 18, 43],\n",
       "       [73, 32,  0],\n",
       "       [46, 26, 63],\n",
       "       [25, 62, 37],\n",
       "       [36,  3,  9],\n",
       "       [19,  8, 34]])"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "score = np.vstack([class1_score,class2_score,class3_score,class4_score,class5_score,class6_score])\n",
    "scroe"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 生成性别数组sex，水平叠加数组sex和score得到data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0 81 89 81]\n",
      " [ 0  9  6 53]\n",
      " [ 0 85 35  3]\n",
      " ...\n",
      " [ 0 90 44 63]\n",
      " [ 1 86 23 76]\n",
      " [ 0 84 38 74]]\n"
     ]
    }
   ],
   "source": [
    "sex_array = np.random.randint(0,2,size=(300,1))\n",
    "score_sex_array = np.hstack((sex_array,score))\n",
    "print(score_sex_array)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 分别计算男女生各科成绩统计指标：最小值、最大值、平均分、中位数、标准差"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 0, 0, 0])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([ 1, 99, 98, 99])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([ 1.        , 50.67142857, 49.20714286, 51.43571429])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([ 1. , 52.5, 48. , 49.5])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([ 0.        , 30.80988776, 26.12346959, 30.1276358 ])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cond1 = score_sex_array[:,0] > 0\n",
    "female_min = np.min(score_sex_array[cond1],axis=0)\n",
    "female_max = np.max(score_sex_array[cond1],axis=0)\n",
    "female_mean = np.mean(score_sex_array[cond1],axis=0)\n",
    "female_median = np.median(score_sex_array[cond1],axis=0)\n",
    "female_std = np.std(score_sex_array[cond1],axis=0)\n",
    "display(female_min,female_max,female_mean,female_median,female_std)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 0, 0, 0])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([ 0, 99, 98, 99])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([ 0.        , 51.06      , 49.69333333, 52.37333333])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([ 0. , 52.5, 49. , 54. ])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([ 0.        , 30.25529816, 27.01516776, 28.79746439])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cond0 = score_sex_array[:,0] < 1\n",
    "male_min = np.min(score_sex_array[cond0],axis=0)\n",
    "male_max = np.max(score_sex_array[cond0],axis=0)\n",
    "male_mean = np.mean(score_sex_array[cond0],axis=0)\n",
    "male_median = np.median(score_sex_array[cond0],axis=0)\n",
    "male_std = np.std(score_sex_array[cond0],axis=0)\n",
    "display(male_min,male_max,male_mean,male_median,male_std)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
